/*
 * Copyright (c) 2007 T.Cogghe, D.Leroux, S.Lévignac, S.Rives
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include "IHM/dialogueFichiers.hh"




IHM::DialogueFichiers::DialogueFichiers(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade)
	: Gtk::FileChooserDialog(cobject) //m_refGlade(refGlade),
{
	Gtk::Button*b;
	getW(refGlade,b,"b_ListeFichiers_OK");
	b->signal_clicked().connect(sigc::mem_fun(*this,&DialogueFichiers::ok));
	getW(refGlade,b,"b_ListeFichiers_Annuler");
	b->signal_clicked().connect(sigc::mem_fun(*this,&DialogueFichiers::annuler));

	Gtk::FileFilter flt_all;
	flt_all.add_pattern(Glib::ustring("*.png"));
	flt_all.add_pattern(Glib::ustring("*.jpg"));
	flt_all.add_pattern(Glib::ustring("*.jpeg"));
	flt_all.add_pattern(Glib::ustring("*.raw"));
	flt_all.set_name("Tous Fichiers (png,jpg,raw)");
	
	Gtk::FileFilter flt_png;
	flt_png.add_pattern(Glib::ustring("*.png"));
	flt_png.set_name("Fichiers PNG");

	Gtk::FileFilter flt_jpg;
	flt_jpg.add_pattern(Glib::ustring("*.jpg"));
	flt_jpg.add_pattern(Glib::ustring("*.jpeg"));
	flt_jpg.set_name("Fichiers JPEG");

	Gtk::FileFilter flt_raw;
	flt_raw.add_pattern(Glib::ustring("*.raw"));
	flt_raw.set_name("Fichiers RAW");

	add_filter(flt_all);
	add_filter(flt_png);
	add_filter(flt_jpg);
	add_filter(flt_raw);
}

IHM::DialogueFichiers::~DialogueFichiers() {}

void IHM::DialogueFichiers::ok() {
	/* liste des fichiers */
	vector<std::string> fichiers=get_filenames();

	vector<std::string>::iterator i=fichiers.begin(),j=fichiers.end();
	while(i!=j) {
		IHM::env->ajoutListe(*i);
		i++;
	}

	/* TODO : effectuer un tri */
	IHM::env->dFic->hide();
}

void IHM::DialogueFichiers::annuler() {
	IHM::env->dFic->hide();
}


